﻿using System.Collections.Generic;
using UnityEngine;
using System;

public class UserSingleton : MonoBehaviour
{

    public static string showName;
    public static string ID;
    public static string Url;
    public static int grade;
    public static string token;
    public static long startTime;
    public static long endTime;
    private static int usedTime;
    private static string issuerId = "100226";
    public static List<int> gradeList = new List<int>();
    public static string ILabTokenUrl;
    public static string ILabStudentMsgUrl;
    public static string ILabStatusUrl;
    public static string StudentMsgUrl;
    public static string StudentLoginUrl;
    public static string StudentRegisterUrl;
    public static string StudentRegisterNameUrl;


    public static int UsedTime
    {
        get
        {
            usedTime = CountMinute(ConvertLongToDateTime(startTime), ConvertLongToDateTime(endTime));
            return usedTime;
        }
    }

    public static string IssuerId
    {
        get
        {
            return issuerId;
        }
    }

    public static void Clear()
    {
        grade = 0;
        gradeList.Clear();
    }

    /// <summary>
    /// long-->datetime
    /// </summary>
    /// <param name="timeStamp"></param>
    /// <returns></returns>
    public static DateTime ConvertLongToDateTime(long timeStamp)
    {
        DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
        long lTime = long.Parse(timeStamp / 1000 + "0000000");
        TimeSpan toNow = new TimeSpan(lTime);
        return dtStart.Add(toNow);
    }
    /// <summary>
    /// datetime-->long
    /// </summary>
    /// <param name="time"></param>
    /// <returns></returns>
    public static long ConvertDateTimeToLong(DateTime time)
    {
        DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
        return (long)(time - startTime).TotalMilliseconds;
    }

    /// <summary>
    /// 计算差值（分钟）
    /// </summary>
    /// <param name="start"></param>
    /// <param name="end"></param>
    /// <returns></returns>
    public static int CountMinute(DateTime start, DateTime end)
    {
        int min = (end - start).Minutes;
        if(min < 1)
        {
            min = 1;
        }
        return min;
    }
}
